package org.dromara.web.controller.sz.claim;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.claim.bo.ClaimAttachBo;
import org.dromara.system.domain.claim.vo.ClaimAttachVo;
import org.dromara.system.service.claim.IClaimAttachService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 理赔附属
 *
 * @author Lion Li
 * @date 2025-11-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sz/attach")
public class ClaimAttachController extends BaseController {

    private final IClaimAttachService claimAttachService;

    /**
     * 查询理赔附属列表
     */
    @SaCheckPermission("system:attach:list")
    @GetMapping("/list")
    public TableDataInfo<ClaimAttachVo> list(ClaimAttachBo bo, PageQuery pageQuery) {
        return claimAttachService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出理赔附属列表
     */
    @SaCheckPermission("system:attach:export")
    @Log(title = "理赔附属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ClaimAttachBo bo, HttpServletResponse response) {
        List<ClaimAttachVo> list = claimAttachService.queryList(bo);
        ExcelUtil.exportExcel(list, "理赔附属", ClaimAttachVo.class, response);
    }

    /**
     * 获取理赔附属详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:attach:query")
    @GetMapping("/{id}")
    public R<ClaimAttachVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(claimAttachService.queryById(id));
    }

    /**
     * 新增理赔附属
     */
    @SaCheckPermission("system:attach:add")
    @Log(title = "理赔附属", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ClaimAttachBo bo) {
        return toAjax(claimAttachService.insertByBo(bo));
    }

    /**
     * 修改理赔附属
     */
    @SaCheckPermission("system:attach:edit")
    @Log(title = "理赔附属", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ClaimAttachBo bo) {
        return toAjax(claimAttachService.updateByBo(bo));
    }

    /**
     * 删除理赔附属
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:attach:remove")
    @Log(title = "理赔附属", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(claimAttachService.deleteWithValidByIds(List.of(ids), true));
    }
}
